/*
 * JTalkerFrontSettings.java
 *
 * Created on 27. Oktober 2003, 11:11
 */

package info.chrm.jtalker;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import info.chrm.helper.*;

/** This class represents the property dialog */
public class JTalkerFrontSettings extends javax.swing.JFrame {
    private JTalkerClientFront parent = null;
    private boolean onInit = true;
    
    
    /** Creates new form JTalkerFrontSettings */
    public JTalkerFrontSettings(JTalkerClientFront _parent) {
	this.parent = _parent;
	this.initComponents();
	this.setupElements();
	this.setSize(500, 320);
	this.jListPropertyPages.setSelectedIndex(0);
	this.showPropertyPanel(0);     	   
	this.setLocationRelativeTo(_parent);
        this.getRootPane().setDefaultButton(this.jButton1);
	this.onInit = false;
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents() {
	   jPanel1 = new javax.swing.JPanel();
	   jButton1 = new javax.swing.JButton();
	   jButton2 = new javax.swing.JButton();
	   jPanel2 = new javax.swing.JPanel();
	   jSplitPane1 = new javax.swing.JSplitPane();
	   jScrollPane1 = new javax.swing.JScrollPane();
	   jListPropertyPages = new javax.swing.JList();
	   jPanel3 = new javax.swing.JPanel();
	   jPanelPropsAccount = new javax.swing.JPanel();
	   jLabel1 = new javax.swing.JLabel();
	   jTextFieldUserName = new javax.swing.JTextField();
	   jButton3 = new javax.swing.JButton();
	   jLabel2 = new javax.swing.JLabel();
	   jPasswordFieldPasswd = new javax.swing.JPasswordField();
	   jCheckBoxSavePasswd = new javax.swing.JCheckBox();
	   jCheckBoxUseSSL = new javax.swing.JCheckBox();
	   jPanelPropsServer = new javax.swing.JPanel();
	   jLabel3 = new javax.swing.JLabel();
	   jTextFieldServerIP = new javax.swing.JTextField();
	   jLabel4 = new javax.swing.JLabel();
	   jLabelAppsBrowser = new javax.swing.JLabel();
	   jLabelAppsEMailClient = new javax.swing.JLabel();
	   jTextFieldAppsBrowser = new javax.swing.JTextField();
	   jTextFieldAppsEMailClient = new javax.swing.JTextField();
	   jTextFieldServerPort = new javax.swing.JTextField();
	   jButton4 = new javax.swing.JButton();
	   jPanelPropsApps = new javax.swing.JPanel();
	   jPanelNotificationApps = new javax.swing.JPanel();
	   jPanelLookAndFeel = new javax.swing.JPanel();
	   jPanelPlugins = new javax.swing.JPanel();
	   jLabelPluginDir = new javax.swing.JLabel();
	   jTextFieldPluginDir = new javax.swing.JTextField();
	   cl = ResourceAnchor.class.getClassLoader();

	   this.addWindowListener(new java.awt.event.WindowAdapter() {
	       public void windowClosing(java.awt.event.WindowEvent evt) {
		   jButton2ActionPerformed(null);
	       }
	   });

	   jButton1.setText("OK");
	   jButton1.addActionListener(new java.awt.event.ActionListener() {
	       public void actionPerformed(java.awt.event.ActionEvent evt) {
		   jButton1ActionPerformed(evt);
	       }
	   });

	   jPanel1.add(jButton1);

	   jButton2.setText("Cancel");
	   jButton2.addActionListener(new java.awt.event.ActionListener() {
	       public void actionPerformed(java.awt.event.ActionEvent evt) {
		   jButton2ActionPerformed(evt);
	       }
	   });

	   jPanel1.add(jButton2);

	   this.getContentPane().add(jPanel1, java.awt.BorderLayout.SOUTH);

	   jPanel2.setLayout(new java.awt.BorderLayout());

	   jListPropertyPages.setModel(new javax.swing.AbstractListModel() {
	       String[] strings = { "Login", "Server", "Apps", "Notification", "Look", "Plugins" };
	       public int getSize() { return strings.length; }
	       public Object getElementAt(int i) { return strings[i]; }
	   });
	   
	   jListPropertyPages.addListSelectionListener(new javax.swing.event.ListSelectionListener(){
	       public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
		   jListPropertiesValueChanged(evt);
	       }
	   });

	   jListPropertyPages.setCellRenderer(new MyListCellRenderer());

	   jScrollPane1.setViewportView(jListPropertyPages);

	   jSplitPane1.setLeftComponent(jScrollPane1);

	   jPanel3.setLayout(new javax.swing.BoxLayout(jPanel3, javax.swing.BoxLayout.Y_AXIS));

	   ////////////////// Account Props /////////////////////////////
	   jPanelPropsAccount.setLayout(null);

	   jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
	   jLabel1.setText("User Name:");
	   jPanelPropsAccount.add(jLabel1);
	   jLabel1.setBounds(0, 10, 110, 30);

	   jTextFieldUserName.setToolTipText("Your JTalker user name");
	   jPanelPropsAccount.add(jTextFieldUserName);
	   jTextFieldUserName.setBounds(120, 10, 123, 30);

	/*jButton3.setText("Create New Account...");
	jButton3.setEnabled(false);
	jButton3.setToolTipText("Lets create you a new JTalker Account");
	jButton3.setMargin(new java.awt.Insets(2, 1, 2, 1));
	jButton3.addActionListener(new java.awt.event.ActionListener() {
	    public void actionPerformed(java.awt.event.ActionEvent evt) {
		jButton3ActionPerformed(evt);
	    }
	});

	   jPanelPropsAccount.add(jButton3);
	   jButton3.setBounds(30, 130, 160, 30);*/

	   jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
	   jLabel2.setText("User Password:");
	   jPanelPropsAccount.add(jLabel2);
	   jLabel2.setBounds(0, 50, 110, 30);

	   jPanelPropsAccount.add(jPasswordFieldPasswd);
	   jPasswordFieldPasswd.setBounds(120, 50, 123, 30);

	   jCheckBoxSavePasswd.setSelected(true);
	   jCheckBoxSavePasswd.setText("Save Password");
	   jCheckBoxSavePasswd.setToolTipText(" Saves Your password in the config file");
	   jPanelPropsAccount.add(jCheckBoxSavePasswd);
	   jCheckBoxSavePasswd.setBounds(120, 90, 120, 26);

	   jPanel3.add(jPanelPropsAccount);

	   ////////////////// Server Props /////////////////////////////
	   jPanelPropsServer.setLayout(null);

	   jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
	   jLabel3.setText("Server Name:");
	   jPanelPropsServer.add(jLabel3);
	   jLabel3.setBounds(0, 10, 110, 30);

	   jTextFieldServerIP.setToolTipText("Servers IP-Adress");
	   jPanelPropsServer.add(jTextFieldServerIP);
	   jTextFieldServerIP.setBounds(120, 10, 123, 30);

	   jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
	   jLabel4.setText("Server Port:");
	   jPanelPropsServer.add(jLabel4);
	   jLabel4.setBounds(0, 50, 110, 30);

	   jTextFieldServerPort.setToolTipText("Servers Port number");
	   jPanelPropsServer.add(jTextFieldServerPort);
	   jTextFieldServerPort.setBounds(120, 50, 123, 30);

	   /*jButton4.setText("Test");
	   jButton4.setToolTipText("Tests if a JTalker server is available");
	   jButton4.setMargin(new java.awt.Insets(2, 1, 2, 1));
	   jButton4.addActionListener(new java.awt.event.ActionListener() {
	       public void actionPerformed(java.awt.event.ActionEvent evt) {
		   jButton4ActionPerformed(evt);
	       }
	   });

	   jPanelPropsServer.add(jButton4);
	   jButton4.setBounds(33, 100, 160, 30);*/

	   jCheckBoxUseSSL.setSelected(true);
	   jCheckBoxUseSSL.setText("Use SSL");
	   jCheckBoxUseSSL.setToolTipText("Use secure connection to server");
	   jPanelPropsServer.add(jCheckBoxUseSSL);
	   jCheckBoxUseSSL.setBounds(120, 90, 120, 26);
	   jPanelPropsServer.add(jCheckBoxUseSSL);

	   jPanel3.add(jPanelPropsServer);

	    
	   ////////////////// Applications Props /////////////////////////////
	   jPanelPropsApps.setLayout(null);

	   jLabelAppsBrowser.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
	   jLabelAppsBrowser.setText("Web Browser:");
	   jPanelPropsApps.add(jLabelAppsBrowser);
	   jLabelAppsBrowser.setBounds(0, 10, 110, 30);

	   jTextFieldAppsBrowser.setToolTipText("Full path to Your favourite browser");
	   jPanelPropsApps.add(jTextFieldAppsBrowser);
	   jTextFieldAppsBrowser.setBounds(120, 10, 123, 30);
	   jTextFieldAppsBrowser.setText("mozilla");

	   jLabelAppsEMailClient.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
	   jLabelAppsEMailClient.setText("Mail Client:");
	   jPanelPropsApps.add(jLabelAppsEMailClient);
	   jLabelAppsEMailClient.setBounds(0, 50, 110, 30);

	   jTextFieldAppsEMailClient.setToolTipText("Full path to Your favourite e-mail client");
	   jTextFieldAppsEMailClient.setText("kmail");
	   jPanelPropsApps.add(jTextFieldAppsEMailClient);
	   jTextFieldAppsEMailClient.setBounds(120, 50, 123, 30);

	   jPanel3.add(jPanelPropsApps);

	   ////////////////// Notification Props /////////////////////////////
	   jPanelNotificationApps.setLayout(new java.awt.GridLayout(2, 1));
	   buttonGroupNotification = new javax.swing.ButtonGroup();
	   buttonGroupNotificationChat = new javax.swing.ButtonGroup();
	   jPanelUSERLIST = new javax.swing.JPanel();
	   jLabelUSERLISTINFO = new javax.swing.JLabel();
	   jRadioButtonUSERLISTNONE = new javax.swing.JRadioButton();
	   jRadioButtonUSERLISTTOFRONT = new javax.swing.JRadioButton();
	   jRadioButtonUSERLISTNOTIBOX = new javax.swing.JRadioButton();
	   jRadioButtonUSERLISTBEEP = new javax.swing.JRadioButton();
	   /*jPanelCHATWINDOW = new javax.swing.JPanel();
	   jRadioButtonCHATWINDOWNONE = new javax.swing.JRadioButton();
	   jRadioButtonCHATWINDOWBEEP = new javax.swing.JRadioButton();*/

	   jPanelUSERLIST.setLayout(new java.awt.GridLayout(5, 0));

	   jPanelUSERLIST.setBorder(new javax.swing.border.TitledBorder("New Mail Notification (Main Window)"));
	   jLabelUSERLISTINFO.setBackground(java.awt.SystemColor.info);
	   jLabelUSERLISTINFO.setText("Occures only, if no chat window is open for affected user.");
	   jLabelUSERLISTINFO.setOpaque(true);
	   jPanelUSERLIST.add(jLabelUSERLISTINFO);

	   buttonGroupNotification.add(jRadioButtonUSERLISTNONE);
	   jRadioButtonUSERLISTNONE.setText("None (only an envelope icon)");
	   jPanelUSERLIST.add(jRadioButtonUSERLISTNONE);

	   buttonGroupNotification.add(jRadioButtonUSERLISTTOFRONT);
	   jRadioButtonUSERLISTTOFRONT.setText("Bring main window to front (get focus)");
	   jPanelUSERLIST.add(jRadioButtonUSERLISTTOFRONT);

	   buttonGroupNotification.add(jRadioButtonUSERLISTNOTIBOX);
	   jRadioButtonUSERLISTNOTIBOX.setText("Show a nice notification box (in background)");
	   jPanelUSERLIST.add(jRadioButtonUSERLISTNOTIBOX);

	   buttonGroupNotification.add(jRadioButtonUSERLISTBEEP);
	   jRadioButtonUSERLISTBEEP.setText("Beep");
	   jPanelUSERLIST.add(jRadioButtonUSERLISTBEEP);

	   jPanelNotificationApps.add(jPanelUSERLIST);
	   jPanelUSERLIST.getAccessibleContext().setAccessibleName("Main Window");

	   /*jPanelCHATWINDOW.setLayout(new java.awt.GridLayout(5, 0));

	   jPanelCHATWINDOW.setBorder(new javax.swing.border.TitledBorder("New Mail Notification (Chat Window)"));
	   buttonGroupNotificationChat.add(jRadioButtonCHATWINDOWNONE);
	   jRadioButtonCHATWINDOWNONE.setText("None");
	   jPanelCHATWINDOW.add(jRadioButtonCHATWINDOWNONE);

	   buttonGroupNotificationChat.add(jRadioButtonCHATWINDOWBEEP);
	   jRadioButtonCHATWINDOWBEEP.setText("Beep");
	   jPanelCHATWINDOW.add(jRadioButtonCHATWINDOWBEEP);

	   jPanelNotificationApps.add(jPanelCHATWINDOW);*/
	   jPanel3.add(jPanelNotificationApps);
	   
	   ////////////////// Look And Feel Props /////////////////////////////
	   jPanelLookAndFeel.setLayout(new java.awt.GridLayout(2, 1));
	   jPanelLookPlafs = new javax.swing.JPanel();
	   jComboBoxAllLooks = new javax.swing.JComboBox();
	   jPanelLookColors = new javax.swing.JPanel();
	   jLabelLookBGColor = new javax.swing.JLabel();
	   jButtonLookBGColor = new javax.swing.JButton();
	   jLabelLookTXColor = new javax.swing.JLabel();
	   jButtonLookTXColor = new javax.swing.JButton();
	   jButtonPlugins = new javax.swing.JButton();
	   jButtonPluginDir = new javax.swing.JButton();

	   jPanelLookPlafs.setBorder(new javax.swing.border.TitledBorder("Look And Feel"));
	   jComboBoxAllLooks.addActionListener(new java.awt.event.ActionListener() {
	       public void actionPerformed(java.awt.event.ActionEvent evt) {
		   jComboBoxAllLooksActionPerformed(evt);
	       }
	   });

	   jPanelLookPlafs.add(jComboBoxAllLooks);

	   jPanelLookAndFeel.add(jPanelLookPlafs);

	   jPanelLookColors.setLayout(new java.awt.GridLayout(2, 2));

	   jPanelLookColors.setBorder(new javax.swing.border.TitledBorder("Colors"));
	   jLabelLookBGColor.setText("Chat Background Color:");
	   jPanelLookColors.add(jLabelLookBGColor);

	   jButtonLookBGColor.setText("Color...");
	   jButtonLookBGColor.addActionListener(new java.awt.event.ActionListener() {
	       public void actionPerformed(java.awt.event.ActionEvent evt) {
		   jButtonLookBGColorActionPerformed(evt);
	       }
	   });

	   jPanelLookColors.add(jButtonLookBGColor);

	   jLabelLookTXColor.setText("Chat Text Color:");
	   jPanelLookColors.add(jLabelLookTXColor);

	   jButtonLookTXColor.setText("Color...");
	   jButtonLookTXColor.addActionListener(new java.awt.event.ActionListener() {
	       public void actionPerformed(java.awt.event.ActionEvent evt) {
		   jButtonLookTXColorActionPerformed(evt);
	       }
	   });

	   jPanelLookColors.add(jButtonLookTXColor);

	   jPanelLookAndFeel.add(jPanelLookColors);

	   jPanel3.add(jPanelLookAndFeel);


	   ////////////////// Applications Props /////////////////////////////
	   jPanelPlugins.setLayout(null);

	   jLabelPluginDir.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
	   jLabelPluginDir.setText("Plugin Dir:");
	   jLabelPluginDir.setBounds(0, 10, 110, 30);
	   jPanelPlugins.add(jLabelPluginDir);

	   jTextFieldPluginDir.setToolTipText("Full path to the plugin directory");
	   jTextFieldPluginDir.setBounds(120, 10, 160, 30);
	   jTextFieldPluginDir.setText(System.getProperty("user.home") + java.io.File.separator + "jt_plugins");
           jTextFieldPluginDir.setEditable(false);
	   jPanelPlugins.add(jTextFieldPluginDir);
	   
           jButtonPlugins.setBounds(120, 50, 160, 30);
	   jButtonPlugins.setText("Plugin Overview");
           jButtonPlugins.addActionListener(new java.awt.event.ActionListener() {
	       public void actionPerformed(java.awt.event.ActionEvent evt) {
		   jButtonPluginsActionPerformed(evt);
	       }
	   });
	   jPanelPlugins.add(jButtonPlugins); 

           jButtonPluginDir.setBounds(285, 10, 30, 30);
	   jButtonPluginDir.setText("...");
           jButtonPluginDir.addActionListener(new java.awt.event.ActionListener() {
	       public void actionPerformed(java.awt.event.ActionEvent evt) {
		   jButtonPluginDirActionPerformed(evt);
	       }
	   });
	   jPanelPlugins.add(jButtonPluginDir); 
	   jPanel3.add(jPanelPlugins);

           
	   //////////////////////////////////////////////////////////////////// 

	   jSplitPane1.setRightComponent(jPanel3);
	   jPanel2.add(jSplitPane1, java.awt.BorderLayout.CENTER);
	   this.getContentPane().add(jPanel2, java.awt.BorderLayout.CENTER);

	   this.setTitle("JTalker Configuration");
	   this.pack();
       }

       private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
	   // CANCEL
           this.setupElements();
	   this.dispose();
       }

       private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
	   // Test if server available
       }

       private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
	   // Create Account
       }
       
       private void jButtonPluginsActionPerformed(java.awt.event.ActionEvent evt) {
	   // Show Plugin Overview
           if(this.parent.myPluginsInfoDialog == null)
                this.parent.myPluginsInfoDialog = new JTalkerClientPluginsInfo(this.parent);
                
           if(this.parent.myPluginsInfoDialog.updatePluginList(this.jTextFieldPluginDir.getText()))
                this.parent.myPluginsInfoDialog.setVisible(true);
       }
       
       private void jButtonPluginDirActionPerformed(java.awt.event.ActionEvent evt) {
           // Select Plugin Dir
           JFileChooser fc = new JFileChooser();
	   fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
	   fc.setCurrentDirectory(new java.io.File(this.jTextFieldPluginDir.getText()));

	   int returnVal = fc.showOpenDialog(this);

	   if (returnVal == JFileChooser.APPROVE_OPTION) {
	       // Open File
	       java.io.File file = fc.getSelectedFile();			
	       String tmpFilename = file.getAbsolutePath();      

               this.jTextFieldPluginDir.setText(tmpFilename + java.io.File.separator);
	   } 		    
       }

       private void jListPropertiesValueChanged(javax.swing.event.ListSelectionEvent evt) {
	   // Add your handling code here:
	   this.showPropertyPanel(this.jListPropertyPages.getSelectedIndex());
       }

       private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
	   // OK    
	   String user = this.jTextFieldUserName.getText();
	   String passwd = new String(this.jPasswordFieldPasswd.getPassword());
	   String serverIP = this.jTextFieldServerIP.getText();
	   String serverPort = this.jTextFieldServerPort.getText();
	   String browser = this.jTextFieldAppsBrowser.getText();
	   String mailClient = this.jTextFieldAppsEMailClient.getText();
	   int notificationType = 0;
	   String guiTextColor = JTalkerClient.getColorAsString(this.jButtonLookTXColor.getBackground());
	   String guiBgColor = JTalkerClient.getColorAsString(this.jButtonLookBGColor.getBackground());
	   String guiPlaf = (String)this.jComboBoxAllLooks.getSelectedItem();
	   String plugindir = this.jTextFieldPluginDir.getText();

	   for (java.util.Enumeration e = this.buttonGroupNotification.getElements() ; e.hasMoreElements() ;) {
	      if(((JRadioButton)e.nextElement()).isSelected())
		 break;
	      notificationType++;
	   }
	   
	   try {
	      this.parent.theClient.serverName = serverIP;
	      this.parent.theClient.portNum = Integer.parseInt(serverPort);
	      this.parent.theClient.userName = user;  
	      this.parent.theClient.userPasswd = passwd;  
	      this.parent.theClient.defaultBrowser = browser;  
	      this.parent.theClient.defaultMailer = mailClient;  
	      this.parent.theClient.newMailNotificationType = notificationType;  
	      this.parent.theClient.guiTextColor = guiTextColor;  
	      this.parent.theClient.guiBgColor = guiBgColor;

	      if(this.jCheckBoxUseSSL.isSelected()) {
		  this.parent.theClient.useSSL = true;
		  // TODO: Only by using strong certs (from keystore)
		  /*
		  // Check for keystore
		  this.parent.theClient.useSSL = false;
		  String keyStore = null;
		 
		  
		  try { 
		   keyStore = System.getProperty("javax.net.ssl.trustStore");
		   if(keyStore != null) {
		      boolean keyStoreOK = new java.io.File(keyStore).canRead();
		      if(!keyStoreOK) {
			 System.err.println("*** Can't read " + keyStore);
		      }
		      else
			 this.parent.theClient.useSSL = true;
		   }	   
		  } catch (Exception _e) {
		      System.err.println("*** Error: " + _e.toString());  
		  }

		  if(!this.parent.theClient.useSSL) {
		     javax.swing.JOptionPane.showMessageDialog(null, 
						   "Keystore not available:\n" + keyStore,
						   "Can't use SSL", 
						   javax.swing.JOptionPane.ERROR_MESSAGE);
		     return;
		  }*/
	      }
	      else
		  this.parent.theClient.useSSL = false;

	      if(!guiPlaf.equals(this.parent.theClient.guiPlaf)) {
		 // Set new LnF
		 this.parent.theClient.guiPlaf = guiPlaf;
		  try {
		     javax.swing.UIManager.setLookAndFeel((String)this.jComboBoxAllLooks.getSelectedItem());
		     javax.swing.SwingUtilities.updateComponentTreeUI(this.parent);	       
		 } catch (Exception _e) {
		     System.out.println("*** Can't set Look'n'Feel!");
		 }		 
	      }
	      
              this.parent.theClient.pluginDir = plugindir;
              this.parent.loadAllPlugins();
	      
              // Ok, lets save all
	      if(this.jCheckBoxSavePasswd.isSelected())
                  this.parent.theClient.savePassword = true;
	      else
                  this.parent.theClient.savePassword = false;		  
                
              this.parent.theClient.saveSettings();
              
	   } catch (Exception _e) { 
	      this.parent.theClient.portNum = 4444;
	      System.err.println("*** Can't set properties: " + _e.toString());
	   } 
     
	   this.dispose();
       }

       /** Select Text Color */
       private void jButtonLookTXColorActionPerformed(java.awt.event.ActionEvent evt) {
	   java.awt.Color newColor = javax.swing.JColorChooser.showDialog(this.jButtonLookTXColor,
                                                  "Choose a custom color",
                                                  this.jButtonLookTXColor.getBackground());
	   if(newColor != null){
	       this.jButtonLookTXColor.setBackground(newColor);            
	   }
    
       }

       /** Select BG Color */
       private void jButtonLookBGColorActionPerformed(java.awt.event.ActionEvent evt) {
	   java.awt.Color newColor = javax.swing.JColorChooser.showDialog(this.jButtonLookBGColor,
						     "Choose a custom color",
						     this.jButtonLookBGColor.getBackground());
	   if(newColor != null){
	       this.jButtonLookBGColor.setBackground(newColor);            
	   }
       }

       /** Try PlaF */
       private void jComboBoxAllLooksActionPerformed(java.awt.event.ActionEvent evt) {	    
	   if(this.onInit)
	      return;

	   this.setVisible(false);

	   try {
	       javax.swing.UIManager.setLookAndFeel((String)this.jComboBoxAllLooks.getSelectedItem());
	       javax.swing.SwingUtilities.updateComponentTreeUI(this);
	       //this.pack();
	       //this.setSize(500, 320);
	   } catch (Exception _e) {
	       System.out.println("*** Can't set Look'n'Feel!");
	   }
	   
	   this.setVisible(true);
       }
	  
       /** Exit the Application */
       private void exitForm(java.awt.event.WindowEvent evt) {
	   //System.exit(0);
       }
       
       /**
	* @param args the command line arguments
	*/
       /*public static void main(String args[]) {
	   new JTalkerFrontSettings().show();
       }*/

       public void setVisible(boolean _yes) {
           this.setupElements();
           super.setVisible(_yes);
       }
       
       private boolean setupElements() {	   
	   this.jTextFieldServerIP.setText(this.parent.theClient.serverName);
	   this.jTextFieldServerPort.setText(String.valueOf(this.parent.theClient.portNum));
	    
	   if(this.parent.theClient.useSSL)
	      this.jCheckBoxUseSSL.setSelected(true);
	   else
	      this.jCheckBoxUseSSL.setSelected(false);
	   
	   this.jTextFieldUserName.setText(this.parent.theClient.userName);            
	   String passwd = this.parent.theClient.userPasswd;
	   if(this.parent.theClient.savePassword) {
	      this.jPasswordFieldPasswd.setText(passwd);
              this.jCheckBoxSavePasswd.setSelected(true);
           } else
              this.jCheckBoxSavePasswd.setSelected(false);
	   
	   this.jTextFieldAppsBrowser.setText(this.parent.theClient.defaultBrowser);            
	   this.jTextFieldAppsEMailClient.setText(this.parent.theClient.defaultMailer);

	   int notificationType = 0;

	   for (java.util.Enumeration e = this.buttonGroupNotification.getElements() ; e.hasMoreElements() ;) {
	      JRadioButton tmpButton = (JRadioButton)e.nextElement();
	      if(notificationType == this.parent.theClient.newMailNotificationType) {
		 tmpButton.setSelected(true);
		 break;
	      }
	      notificationType++;
	   }

           if(this.onInit) {
               // Show all available Looks
               javax.swing.UIManager.LookAndFeelInfo[] lfs = javax.swing.UIManager.getInstalledLookAndFeels();
        
               for(int i=0; i<lfs.length; i++) {
                   this.jComboBoxAllLooks.addItem(lfs[i].getClassName());
               }

               this.jComboBoxAllLooks.setSelectedItem(this.parent.theClient.guiPlaf);
           }

	   // Chat colors
	   this.jButtonLookTXColor.setBackground(Color.decode(this.parent.theClient.guiTextColor));
	   this.jButtonLookBGColor.setBackground(Color.decode(this.parent.theClient.guiBgColor));
	  
           // Plugin Directory 
	   this.jTextFieldPluginDir.setText(this.parent.theClient.pluginDir);
           
	   return true;
       }
       
       private void showPropertyPanel(int _pane) {
	   this.jPanelPropsAccount.setVisible(false);
	   this.jPanelPropsServer.setVisible(false);
	   this.jPanelPropsApps.setVisible(false);
	   this.jPanelNotificationApps.setVisible(false);
	   this.jPanelLookAndFeel.setVisible(false);
	   this.jPanelPlugins.setVisible(false);
	   
	   if(_pane == 0)
	       this.jPanelPropsAccount.setVisible(true);
	   else if(_pane == 1)
	       this.jPanelPropsServer.setVisible(true);
	   else if(_pane == 2)
	       this.jPanelPropsApps.setVisible(true);        
	   else if(_pane == 3)
	       this.jPanelNotificationApps.setVisible(true);        
	   else if(_pane == 4)
	       this.jPanelLookAndFeel.setVisible(true);        
	   else if(_pane == 5)
	       this.jPanelPlugins.setVisible(true);        
	   else
	       return;
       }    
       
       // Variables declaration - do not modify
       private javax.swing.JButton jButton1;
       private javax.swing.JButton jButton2;
       private javax.swing.JButton jButton3;
       private javax.swing.JButton jButton4;
       private javax.swing.JCheckBox jCheckBoxSavePasswd;
       private javax.swing.JCheckBox jCheckBoxUseSSL;
       private javax.swing.JLabel jLabel1;
       private javax.swing.JLabel jLabel2;
       private javax.swing.JLabel jLabel3;
       private javax.swing.JLabel jLabel4;
       private javax.swing.JLabel jLabelAppsBrowser;
       private javax.swing.JLabel jLabelAppsEMailClient;
       private javax.swing.JList jListPropertyPages;
       private javax.swing.JPanel jPanel1;
       private javax.swing.JPanel jPanel2;
       private javax.swing.JPanel jPanel3;
       private javax.swing.JPanel jPanelPropsAccount;
       private javax.swing.JPanel jPanelPropsServer;
       private javax.swing.JPanel jPanelPropsApps;
       private javax.swing.JPanel jPanelNotificationApps;
       private javax.swing.JPanel jPanelLookAndFeel;
       private javax.swing.JPanel jPanelPlugins;
       private javax.swing.JPasswordField jPasswordFieldPasswd;
       private javax.swing.JScrollPane jScrollPane1;
       private javax.swing.JSplitPane jSplitPane1;
       private javax.swing.JTextField jTextFieldServerIP;
       private javax.swing.JTextField jTextFieldServerPort;
       private javax.swing.JTextField jTextFieldUserName;
       private javax.swing.JTextField jTextFieldAppsBrowser;
       private javax.swing.JTextField jTextFieldAppsEMailClient;
       private ClassLoader cl;
       private javax.swing.ButtonGroup buttonGroupNotification;
       private javax.swing.ButtonGroup buttonGroupNotificationChat;
       private javax.swing.JLabel jLabelUSERLISTINFO;
       private javax.swing.JPanel jPanelCHATWINDOW;
       private javax.swing.JPanel jPanelUSERLIST;
       private javax.swing.JRadioButton jRadioButtonCHATWINDOWBEEP;
       private javax.swing.JRadioButton jRadioButtonCHATWINDOWNONE;
       private javax.swing.JRadioButton jRadioButtonUSERLISTBEEP;
       private javax.swing.JRadioButton jRadioButtonUSERLISTNONE;
       private javax.swing.JRadioButton jRadioButtonUSERLISTNOTIBOX;
       private javax.swing.JRadioButton jRadioButtonUSERLISTTOFRONT;

       private javax.swing.JButton jButtonLookBGColor;
       private javax.swing.JButton jButtonLookTXColor;
       private javax.swing.JComboBox jComboBoxAllLooks;
       private javax.swing.JLabel jLabelLookBGColor;
       private javax.swing.JLabel jLabelLookTXColor;
       private javax.swing.JPanel jPanelLookColors;
       private javax.swing.JPanel jPanelLookPlafs;

       private javax.swing.JTextField jTextFieldPluginDir;
       private javax.swing.JLabel jLabelPluginDir;
       private javax.swing.JButton jButtonPlugins;
       private javax.swing.JButton jButtonPluginDir;
       // End of variables declaration



   /** This class represents a List Row */
   class MyListCellRenderer extends JLabel implements ListCellRenderer {
      private ImageIcon userSettingsIcon = 
	 new ImageIcon(cl.getResource("icons/user_settings.png"));
      private ImageIcon serverSettingsIcon = 
	 new ImageIcon(cl.getResource("icons/server.png"));
      private ImageIcon appsSettingsIcon = 
	 new ImageIcon(cl.getResource("icons/apps.png"));
      private ImageIcon notificationIcon = 
	 new ImageIcon(cl.getResource("icons/notification.png"));
      private ImageIcon lookIcon = 
	 new ImageIcon(cl.getResource("icons/look.png"));
      private ImageIcon pluginIcon = 
	 new ImageIcon(cl.getResource("icons/plugins.png"));

      // This is the only method defined by ListCellRenderer.
      // We just reconfigure the JLabel each time we're called.

      public Component getListCellRendererComponent(
       JList _list,
       Object _value,            // value to display
       int _index,               // cell index
       boolean _isSelected,      // is the cell selected
       boolean _cellHasFocus)    // the list and the cell have the focus
      {
	 if(_value == null)
	    return null;	 
	 String rowText = (String)_value;
	 
	 if(rowText.equals("Login"))
	    this.setIcon(this.userSettingsIcon);
	 else if(rowText.equals("Server"))
	    this.setIcon(this.serverSettingsIcon);
	 else if(rowText.equals("Apps"))
	    this.setIcon(this.appsSettingsIcon);
	 else if(rowText.equals("Notification"))
	    this.setIcon(this.notificationIcon);
	 else if(rowText.equals("Look"))
	    this.setIcon(this.lookIcon);
	 else if(rowText.equals("Plugins"))
	    this.setIcon(this.pluginIcon);

	 this.setText(rowText + "  ");
	 
	 if (_isSelected) {
	     this.setBackground(_list.getSelectionBackground());
	     this.setForeground(_list.getSelectionForeground());
	 }
	 else {
	     this.setBackground(_list.getBackground());
	     this.setForeground(_list.getForeground());
	 }
	 
	 this.setEnabled(_list.isEnabled());
	 this.setFont(_list.getFont());
	 this.setOpaque(true);
	 
	 return this;
      }
   }
}


       

